<?php
namespace App\Http\Controllers;

use App\Http\Logic\AccountLogic;
use App\Http\Requests\Account\AddSwtRequest;
use App\Http\Requests\Account\AddWalletRequest;
use App\Http\Requests\Account\DeleteWalletRequest;
use App\Http\Requests\Account\QueryAccountBalanceRequest;
use App\Http\Requests\Account\QueryAccountRequest;
use App\Http\Requests\Account\QueryWalletAddressRequest;
use Illuminate\Http\JsonResponse;

class AccountController extends BaseController
{
    /**
     * @notes 获取钱包列表
     * @param \App\Http\Requests\Account\QueryAccountRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/04/09 15:09
     */
    public function queryAccount(QueryAccountRequest $request) : JsonResponse
    {
        $user_id = auth() -> user() -> id;

        $res = AccountLogic::queryAccount($user_id);

        if(false === $res) {
            return $this->error(AccountLogic::getErrorMessage());
        }

        return $this->success($res);
    }
    /**
     * @notes 获取钱包地址
     * @param \App\Http\Requests\Account\QueryWalletAddressRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/04/09 17:05
     */
    public function queryWalletAddress(QueryWalletAddressRequest $request) : JsonResponse
    {
        $params = $request->all();

        $res = AccountLogic::queryWalletAddress($params);

        if(false === $res) {
            return $this->error(\App\Http\Logic\AccountLogic::getErrorMessage());
        }

        return $this->success($res);
    }
    /**
     * @notes 增加钱包
     * @param \App\Http\Requests\Account\AddWalletRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/03/19 16:14
     */
    public function addWallet(AddWalletRequest $request) : JsonResponse
    {
        $user_id = auth() -> user() -> id;

        $res = \App\Http\Logic\AccountLogic::addWallet($user_id);

        if(false === $res) {
            return $this->error(AccountLogic::getErrorMessage());
        }

        return $this->success($res);
    }
    /**
     * @notes 删除钱包
     * @param \App\Http\Requests\Account\DeleteWalletRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/04/09 15:41
     */
    public function deleteWallet(DeleteWalletRequest $request) : JsonResponse
    {
        $wallet_id = $request->input('walletId');

        $user_id = auth() -> user() -> id;

        $res = \App\Http\Logic\AccountLogic::deleteWallet($user_id, $wallet_id);

        if(false === $res) {
            return $this->error(\App\Http\Logic\AccountLogic::getErrorMessage());
        }

        return $this->success();
    }
    /**
     * @notes 增加SWT
     * @param \App\Http\Requests\Account\AddSwtRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/04/09 17:06
     */
    public function addSwt(AddSwtRequest $request) : JsonResponse
    {
        $user_id = $request->input('user_id');

        $total = $request->input('total');

        $res = \App\Http\Logic\AccountLogic::addSwt($user_id, $total);

        if(false === $res) {
            return $this->error(\App\Http\Logic\AccountLogic::getErrorMessage());
        }

        return $this->success();
    }
    /**
     * @notes 获取账户总资产
     * @param \App\Http\Requests\Account\QueryAccountBalanceRequest $request
     * @return JsonResponse
     * @author Evil丿
     * @date 2025/04/11 16:07
     */
    public function queryAccountBalance(QueryAccountBalanceRequest $request) : JsonResponse
    {
        $user_id = auth() -> user() -> id;

        $res = AccountLogic::queryAccountBalance($user_id);

        if(false === $res) {
            return $this->error(\App\Http\Logic\AccountLogic::getErrorMessage());
        }

        return $this->success($res);
    }
}
